<template>
  <custom-modal-page :visible.sync="visible">
    <div class="device-home-container">
      <div class="screen-conditions-container">
        <ScreenConditions :isDataType="false">
          <template slot="conditions">
            <a-select placeholder="请选择设备" v-model="condition.equCode">
              <a-select-option
                :value="item.equCode"
                v-for="item in condition.equSource"
                :key="item.id"
              >
                {{ item.equName }}
              </a-select-option>
            </a-select>
          </template>
          <template slot="operate">
            <a-button type="primary" @click="search()"> 查询 </a-button>
            <a-button class="back-button" @click="goBack()"> 返回 </a-button>
          </template>
        </ScreenConditions>
      </div>
      <div class="header" header="实时监测">
        <div>
          <a-button type="primary" @click="gotoRecord()">
            历史监测记录
          </a-button>
          <a-button type="primary" @click="gotoWarning()"> 预警推送 </a-button>
        </div>
      </div>
      <div class="main">
        <div class="body">
          <div class="top">
            <div class="left">
              <div class="title">前车参数</div>
              <div class="hook-state">
                <div class="state">
                  <span class="fillet">●</span>前车主钩重量：
                  <span class="nums"> {{ form.j7 }} </span>t
                </div>
                <div class="state">
                  <span class="fillet">●</span>前车副钩重量：
                  <span class="nums">{{ form.j10 }} </span>t
                </div>
                <div class="state">
                  <span class="fillet">●</span>前车主钩深度：
                  <span class="nums"> {{ form.j8 }} </span>m
                </div>
                <div class="state">
                  <span class="fillet">●</span>前车副钩深度：
                  <span class="nums">{{ form.j11 }} </span>m
                </div>
                <div class="state">
                  <span class="fillet">●</span>前车主钩速度：
                  <span class="nums">{{ form.j9 }} </span>m/s
                </div>
                <div class="state">
                  <span class="fillet">●</span> 前车副钩速度：
                  <span class="nums"> {{ form.j12 }} </span>m/s
                </div>
                <div class="state" style="width: 100%">
                  <span class="fillet">●</span> 前车位置：
                  <span class="nums">{{ form.j20 }} </span>m
                </div>
              </div>
              <div class="qc-container">
                <div class="item">
                  <div :class="[checkImg(form.j73), 'icon']"></div>
                  <div class="text">
                    前车前进：<span :class="[checkColor(form.j73), 'status']">
                      {{ checkState(form.j73) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkImg(form.j74), 'icon']"></div>
                  <div class="text">
                    前车后退：<span :class="[checkColor(form.j74), 'status']">
                      {{ checkState(form.j74) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkImg(form.j77), 'icon']"></div>
                  <div class="text">
                    前主卷扬提钩：<span
                      :class="[checkColor(form.j77), 'status']"
                    >
                      {{ checkState(form.j77) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkImg(form.j78), 'icon']"></div>
                  <div class="text">
                    前主卷扬落钩：<span
                      :class="[checkColor(form.j78), 'status']"
                    >
                      {{ checkState(form.j78) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkImg(form.j79), 'icon']"></div>
                  <div class="text">
                    前副卷扬提钩：<span
                      :class="[checkColor(form.j79), 'status']"
                    >
                      {{ checkState(form.j79) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkImg(form.j80), 'icon']"></div>
                  <div class="text">
                    前副卷扬落钩：<span
                      :class="[checkColor(form.j80), 'status']"
                    >
                      {{ checkState(form.j80) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j89), 'icon']"></div>
                  <div class="text">
                    前车前限位：<span :class="[checkClass(form.j89), 'status']">
                      {{ checkResult(form.j89) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j90), 'icon']"></div>
                  <div class="text">
                    前车后限位：<span :class="[checkClass(form.j90), 'status']">
                      {{ checkResult(form.j90) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j93), 'icon']"></div>
                  <div class="text">
                    前主卷扬上限位：<span
                      :class="[checkClass(form.j93), 'status']"
                    >
                      {{ checkResult(form.j93) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j94), 'icon']"></div>
                  <div class="text">
                    前主卷扬下限位：<span
                      :class="[checkClass(form.j94), 'status']"
                    >
                      {{ checkResult(form.j94) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j95), 'icon']"></div>
                  <div class="text">
                    前副卷扬上限位：<span
                      :class="[checkClass(form.j95), 'status']"
                    >
                      {{ checkResult(form.j95) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j96), 'icon']"></div>
                  <div class="text">
                    前副卷扬下限位：<span
                      :class="[checkClass(form.j96), 'status']"
                    >
                      {{ checkResult(form.j96) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j101), 'icon']"></div>
                  <div class="text">
                    前主卷扬超载：<span
                      :class="[checkClass(form.j101), 'status']"
                    >
                      {{ checkResult(form.j101) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j102), 'icon']"></div>
                  <div class="text">
                    前主卷扬超速：<span
                      :class="[checkClass(form.j102), 'status']"
                    >
                      {{ checkResult(form.j102) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j103), 'icon']"></div>
                  <div class="text">
                    前副卷扬超载：<span
                      :class="[checkClass(form.j103), 'status']"
                    >
                      {{ checkResult(form.j103) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j104), 'icon']"></div>
                  <div class="text">
                    前副卷扬超速：<span
                      :class="[checkClass(form.j104), 'status']"
                    >
                      {{ checkResult(form.j104) }}
                    </span>
                  </div>
                </div>
              </div>
            </div>
            <div class="center">
              <div class="time">
                <div class="item">
                  <div>累计工作时间</div>
                  <div class="total">
                    {{ form.j135 }}
                  </div>
                </div>
                <div class="item">
                  <div>累计工作次数</div>
                  <div class="total">
                    {{ form.j136 }}<span class="unit">次</span>
                  </div>
                </div>
                <div class="item">
                  <div>本次工作时间</div>
                  <div class="total">
                    {{ form.j137 }}
                  </div>
                </div>
              </div>
              <div class="bg">
                <img
                  src="https://jszhgd.cn/static/pc/equipment-app/lmd_2.png"
                />
              </div>
            </div>
            <div class="right">
              <div class="title">后车参数</div>
              <div class="hook-state">
                <div class="state">
                  <span class="fillet">●</span>后车主钩重量：
                  <span class="nums">{{ form.j13 }} </span>t
                </div>
                <div class="state">
                  <span class="fillet">●</span>后车副钩重量：
                  <span class="nums"> {{ form.j16 }} </span>t
                </div>
                <div class="state">
                  <span class="fillet">●</span>后车主钩深度：
                  <span class="nums">{{ form.j14 }} </span>m
                </div>
                <div class="state">
                  <span class="fillet">●</span>后车副钩深度：
                  <span class="nums">{{ form.j17 }} </span>m
                </div>
                <div class="state">
                  <span class="fillet">●</span>后车主钩速度：
                  <span class="nums">{{ form.j15 }} </span>m/s
                </div>
                <div class="state">
                  <span class="fillet">●</span>后车副钩速度：
                  <span class="nums">{{ form.j18 }} </span>m/s
                </div>
                <div class="state" style="width: 100%">
                  <span class="fillet">●</span>后车位置：
                  <span class="nums"> {{ form.j21 }} </span>m
                </div>
              </div>
              <div class="qc-container">
                <div class="item">
                  <div :class="[checkImg(form.j75), 'icon']"></div>
                  <div class="text">
                    后车前进：<span :class="[checkColor(form.j75), 'status']">
                      {{ checkState(form.j75) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkImg(form.j76), 'icon']"></div>
                  <div class="text">
                    后车后退：<span :class="[checkColor(form.j76), 'status']">
                      {{ checkState(form.j76) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkImg(form.j81), 'icon']"></div>
                  <div class="text">
                    后主卷扬提钩：<span
                      :class="[checkColor(form.j81), 'status']"
                    >
                      {{ checkState(form.j81) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkImg(form.j82), 'icon']"></div>
                  <div class="text">
                    后主卷扬落钩：<span
                      :class="[checkColor(form.j82), 'status']"
                    >
                      {{ checkState(form.j82) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkImg(form.j83), 'icon']"></div>
                  <div class="text">
                    后副卷扬提钩：<span
                      :class="[checkColor(form.j83), 'status']"
                    >
                      {{ checkState(form.j83) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkImg(form.j84), 'icon']"></div>
                  <div class="text">
                    后副卷扬落钩：<span
                      :class="[checkColor(form.j84), 'status']"
                    >
                      {{ checkState(form.j84) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j91), 'icon']"></div>
                  <div class="text">
                    后车前限位：<span :class="[checkClass(form.j91), 'status']">
                      {{ checkResult(form.j91) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j92), 'icon']"></div>
                  <div class="text">
                    后车后限位：<span :class="[checkClass(form.j92), 'status']">
                      {{ checkResult(form.j92) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j97), 'icon']"></div>
                  <div class="text">
                    后主卷扬上限位：<span
                      :class="[checkClass(form.j97), 'status']"
                    >
                      {{ checkResult(form.j97) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j98), 'icon']"></div>
                  <div class="text">
                    后主卷扬下限位：<span
                      :class="[checkClass(form.j98), 'status']"
                    >
                      {{ checkResult(form.j98) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j99), 'icon']"></div>
                  <div class="text">
                    后副卷扬上限位：<span
                      :class="[checkClass(form.j99), 'status']"
                    >
                      {{ checkResult(form.j99) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j100), 'icon']"></div>
                  <div class="text">
                    后副卷扬下限位：<span
                      :class="[checkClass(form.j100), 'status']"
                    >
                      {{ checkResult(form.j100) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j105), 'icon']"></div>
                  <div class="text">
                    后主卷扬超载：<span
                      :class="[checkClass(form.j105), 'status']"
                    >
                      {{ checkResult(form.j105) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j106), 'icon']"></div>
                  <div class="text">
                    后主卷扬超速：<span
                      :class="[checkClass(form.j106), 'status']"
                    >
                      {{ checkResult(form.j106) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j107), 'icon']"></div>
                  <div class="text">
                    后副卷扬超载：<span
                      :class="[checkClass(form.j107), 'status']"
                    >
                      {{ checkResult(form.j107) }}
                    </span>
                  </div>
                </div>
                <div class="item">
                  <div :class="[checkIcon(form.j108), 'icon']"></div>
                  <div class="text">
                    后副卷扬超速：<span
                      :class="[checkClass(form.j108), 'status']"
                    >
                      {{ checkResult(form.j108) }}
                    </span>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="bottom">
            <div class="item">
              <div class="title">整车参数</div>
              <div class="complete">
                <div class="position">
                  <span class="fillet">●</span>整车位置(左)：
                  <span class="nums">{{ form.j19 }} </span>m
                </div>
                <div class="car">
                  <div :class="[checkImg(form.j71), 'icon']"></div>
                  <div>
                    整车左行：<span :class="[checkColor(form.j71), 'status']">
                      {{ checkState(form.j71) }}
                    </span>
                  </div>
                </div>
                <div class="car">
                  <div :class="[checkImg(form.j72), 'icon']"></div>
                  <div>
                    整车右行：<span :class="[checkColor(form.j72), 'status']">
                      {{ checkState(form.j72) }}
                    </span>
                  </div>
                </div>
              </div>
              <div class="complete">
                <div class="position">
                  <span class="fillet">●</span>整车位置(右)（大跨度）：
                  <span class="nums">{{ form.j23 }} </span>m
                </div>
                <div class="car">
                  <div :class="[checkIcon(form.j87), 'icon']"></div>
                  <div>
                    整车左限位：<span :class="[checkClass(form.j87), 'status']">
                      {{ checkResult(form.j87) }}
                    </span>
                  </div>
                </div>
                <div class="car">
                  <div :class="[checkIcon(form.j88), 'icon']"></div>
                  <div>
                    整车右限位：<span :class="[checkClass(form.j88), 'status']">
                      {{ checkResult(form.j88) }}
                    </span>
                  </div>
                </div>
              </div>
            </div>
            <div class="item">
              <div class="title">监测参数</div>
              <div class="complete">
                <div class="position">
                  <span class="fillet">●</span>风级：
                  <span class="nums">{{ form.j22 }} </span>
                </div>
                <div class="position">
                  <span class="fillet">●</span>水平x倾角：
                  <span class="nums">{{ form.j26 }} </span>°
                </div>
                <div class="position">
                  <span class="fillet">●</span>垂直1：
                  <span class="nums">{{ form.j28 }} </span>°
                </div>
                <div class="car">
                  <div :class="[checkIcon(form.j109), 'icon']"></div>
                  <div>
                    风速报警：<span :class="[checkClass(form.j109), 'status']">
                      {{ checkResult(form.j109) }}
                    </span>
                  </div>
                </div>
              </div>
              <div class="complete">
                <div class="position">
                  <span class="fillet">●</span> 风速：
                  <span class="nums"> {{ form.j25 }} </span>m/s
                </div>
                <div class="position">
                  <span class="fillet">●</span>水平y倾角：
                  <span class="nums">{{ form.j27 }} </span>°
                </div>
                <div class="position">
                  <span class="fillet">●</span>垂直2：
                  <span class="nums">{{ form.j29 }} </span>°
                </div>
                <div class="car"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 历史监测记录 -->
    <monitorRecordPage
      :visible.sync="monitorRecordVisible"
      :equCode="condition.equCode"
    ></monitorRecordPage>
    <!-- 预警推送 -->
    <warningPage
      :visible.sync="warningVisible"
      :equCode="condition.equCode"
    ></warningPage>
  </custom-modal-page>
</template>

<script>
import moment from "moment";
import monitorRecordPage from "./monitorRecord.vue";
import warningPage from "./warning.vue";
import {
  getLMDEquipment,
  setLMDSpecial,
} from "@/api/wisdom-beam/collect-app.js";
export default {
  components: {
    monitorRecordPage,
    warningPage,
  },
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    equCode: {
      type: String,
      default: "",
    },
  },
  watch: {
    visible: {
      handler(val) {
        this.$emit("update:visible", val);
        if (val) {
          this.getEquipmentData();
        }
      },
      immediate: true,
    },
  },
  data() {
    return {
      refresh: "",
      condition: {
        equSource: [],
        equCode: "",
      },
      //历史监测记录
      monitorRecordVisible: false,
      //预警推送
      warningVisible: false,
      form: {},
    };
  },
  methods: {
    checkIcon(val) {
      switch (val) {
        case "false":
          return "normal-icon";
        case "true":
          return "error-icon";
        default:
          return "";
      }
    },
    checkClass(val) {
      switch (val) {
        case "false":
          return "normal";
        case "true":
          return "error";
        default:
          return "cancel";
      }
    },
    checkResult(val) {
      switch (val) {
        case "false":
          return "正常";
        case "true":
          return "异常";
        default:
          return "--";
      }
    },
    //J71 ~ J84  状态校验
    checkState(val) {
      switch (val) {
        case "false":
          return "未操作";
        case "true":
          return "正在执行";
        default:
          return "--";
      }
    },
    checkColor(val) {
      switch (val) {
        case "false":
          return "error";
        case "true":
          return "normal";
        default:
          return "cancel";
      }
    },
    checkImg(val) {
      switch (val) {
        case "false":
          return "error-icon";
        case "true":
          return "normal-icon";
        default:
          return "";
      }
    },

    goBack() {
      this.$emit("update:visible", false);
      this.refresh && clearInterval(this.refresh);
    },

    getDuration(seconds) {
      let duration = moment.duration(seconds, "seconds");
      let hours = duration.hours();
      return hours;
    },

    gotoRecord() {
      this.monitorRecordVisible = true;
      this.refresh && clearInterval(this.refresh);
    },

    gotoWarning() {
      this.warningVisible = true;
      this.refresh && clearInterval(this.refresh);
    },

    //查询所有设备
    getEquipmentData() {
      return new Promise((resolve, reject) => {
        getLMDEquipment()
          .then((res) => {
            let { data } = res;
            this.condition.equSource = data?.result || [];
            resolve();
          })
          .catch((_) => {
            this.condition.equSource = [];
            reject();
          })
          .finally((_) => {
            this.condition.equCode = this.equCode;
            this.getData();
            //定时刷新数据
            this.refresh = setInterval((_) => {
              this.getData();
            }, 10000);
          });
      });
    },

    getData() {
      return new Promise((resolve, reject) => {
        let { equCode } = this.condition;
        setLMDSpecial({ equCode })
          .then((res) => {
            let { data } = res;
            this.form = data?.result || {};
            resolve();
          })
          .catch((_) => {
            this.form = {};
            reject();
          });
      });
    },
  },
};
</script>

<style lang="less" scoped>
.device-home-container {
  height: 100%;
  .flex();
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
  padding: 0 0px 10px 10px;
  .screen-conditions-container {
    margin-right: 0px;
    .back-button {
      color: var(--primary-color);
      background: #f1f2f7 !important;
      border: none;
      position: absolute;
      right: 20px;
    }
  }
  .header {
    margin: 10px 0px 10px 0;
    padding: 5px 20px;
    background-color: #fff;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    &::before {
      content: attr(header);
      height: 18px;
      border-left: 3px solid var(--primary-color);
      padding-left: 10px;
      font-size: 18px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #525a5d;
      line-height: 18px;
    }
  }
  .main {
    flex: 1;
    height: 100%;
    .custom-scrollbar();
    overflow: overlay !important;
    .body {
      width: 1656px;
      height: 834px;
      .title {
        font-size: 18px;
        color: #0068b7;
      }
      .icon {
        width: 32px;
        height: 32px;
        margin-right: 10px;
      }
      .normal-icon {
        background: url("https://jszhgd.cn/static/pc/equipment-app/green-light.png")
          no-repeat center center;
        background-size: 100% 100%;
      }
      .error-icon {
        background: url("https://jszhgd.cn/static/pc/equipment-app/red-light.png")
          no-repeat center center;
        background-size: 100% 100%;
      }

      .nums {
        color: #2b2c30;
        font-size: 20px;
      }

      .status {
        font-size: 16px;
        font-weight: bold;
      }
      .normal {
        color: #2fba4b;
      }
      .error {
        color: #ff3f4a;
      }
      .cancel {
        color: #aab0bc;
      }

      .fillet {
        color: #0068b7;
        margin-right: 5px;
      }

      .top {
        .flex();
        .left,
        .right {
          width: 480px;
          height: 670px;
          background: #ffffff;
          box-sizing: border-box;
          padding: 20px 16px;
          .hook-state {
            .flex();
            flex-wrap: wrap;
            font-size: 16px;
            color: #525a5d;
            .state {
              width: 224px;
              margin-bottom: 10px;
            }
          }
          .qc-container {
            .flex();
            flex-wrap: wrap;
            .item {
              width: 224px;
              .flex();
              align-items: center;
              margin-bottom: 20px;
              .text {
                font-size: 16px;
                color: #525a5d;
              }
              &:nth-last-child(2) {
                margin-bottom: 0;
              }
              &:nth-last-child(1) {
                margin-bottom: 0;
              }
            }
          }
        }
        .center {
          margin: 0 10px;
          width: 676px;
          height: 670px;
          background: #ffffff;
          box-sizing: border-box;
          padding: 20px 30px;
          .time {
            margin: 0 20px;
            .flex();
            align-items: center;
            justify-content: space-between;
            .item {
              width: 178px;
              height: 90px;
              background: #eef8ff;
              border-radius: 4px;
              .flex();
              flex-direction: column;
              align-items: center;
              justify-content: center;
              font-size: 16px;
              color: #0068b7;
              .total {
                font-weight: bold;
                font-size: 16px;
                overflow: hidden;
                text-overflow: ellipsis;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                -webkit-line-clamp: 1;
              }
              .unit {
                font-size: 16px;
                font-weight: normal;
              }
            }
          }
          .bg {
            margin-top: 60px;
            flex: 1;
            img {
              width: 588px;
              height: 422px;
            }
          }
        }
      }
      .bottom {
        margin-top: 10px;
        .flex();
        .item {
          width: 822px;
          height: 154px;
          background: #ffffff;
          margin-right: 10px;
          box-sizing: border-box;
          padding: 20px 16px;
          &:last-of-type {
            margin-right: 0;
          }
          .complete {
            .flex();
            align-items: center;
            justify-content: space-between;
            margin-top: 10px;
            .position {
              font-size: 16px;
              color: #525a5d;
              width: 290px;
              .flex();
              align-items: center;
            }
            .car {
              font-size: 16px;
              color: #525a5d;
              width: 220px;
              .flex();
              align-items: center;
            }
          }
        }
      }
    }
  }
}
</style>
